<%@ page contentType="text/html; charset=utf-8"%>
<html>
<head>
    <title>远程监控主机</title>
    <script type="text/javascript" src="moveDiv.js"></script>
    <script type="text/javascript">
    var w;
    var h;
    var screen_x=0;
    var screen_y=0;
    var screen_div;
    var kp=0;
    var kr=0;
    var mp=0;
    var mr=0;
    var mw=0;
    var updateimg=true;
    var loadOk =true;
    var hosting = "${param.host}";
    var robot = 0;
    var parent_div;
    
    function update_xy(){
         screen_x = parseInt(((event.x - parent_div.style.pixelLeft)/w)*window.screen.width);
         screen_y = parseInt(((event.y - parent_div.style.pixelTop-10)/h)*window.screen.height);
         //alert((event.x - parent_div.style.pixelLeft)/w+":"+window.screen.width+":"+screen_x+","+screen_y);
        
         updateimg=true;
         setTimeout("__update()",100);
    }
    
    window.onload = function (){
        	initWindow();
		}
		
    function update_mousedown(){
    
    }
    
    function update_mouseup(){
    
    }
    
    function initWindow(){
        screen_div = document.getElementById("divTmp_content");
        parent_div = document.getElementById("divTmp");
        parent_div.onmousedown   = div_mousedown;
        parent_div.onmouseup     = div_mouseup;
        document.body.onmousemove = _resize;
        screen_div.onmousemove = update_xy;
        document.body.onkeyup = function(){kr = event.keyCode;updateimg=true;__update()};
        document.body.onkeydown = function(){kp = event.keyCode;updateimg=true;__update()};
        document.body.onmousedown = function(){mp = event.Code;updateimg=false;/*alert("mp:"+mp);*/__update()};
        document.body.onmouseup = function(){mr = event.Code;updateimg=true;/*alert("mr:"+mr);*/__update()};
        
        __update();
    }
    
    function __update(){
    	if(!loadOk)return;
        var parent_div = document.getElementById("divTmp");
        w = parent_div.style.pixelWidth;
        h = parent_div.style.pixelHeight-10;
        
        var srcurl = "http://192.168.1.120:9090/Wind/RemoteScreen?img=true&host="+hosting+"&width="+w+"&height="+h;
				if(updateimg){
					srcurl=srcurl+"&img=true";
        			updateimg =false;
				}
        if(screen_x > 0 && screen_y > 0){
            srcurl=srcurl+"&x="+screen_x+"&y="+screen_y;
            screen_x=0;
            screen_y=0;
        }
        if(kr>0){
            srcurl = srcurl+"&kr="+kr;
            kr=0;
        }
        if(kp>0){
            srcurl = srcurl+"&kp="+kp;
            kp=0;
        }
        if(mp>0){
            srcurl = srcurl+"&mp="+mp;
            mp=0;
        }
        if(mr>0){
            srcurl = srcurl+"&mr="+mr;
            mr=0;
        }
        loadOk =false;
        var img = new Image(w,h);
        img.src=srcurl;
        img.onload=loading;
    }
    
    function loading(){
        screen_div.style.backgroundImage = "url("+this.src+")";
        loadOk =true;
    }
    </script>
    
</head>
<body>
     <div id = "divTmp"  style="border:solid 3px #33bbff; left:10px;top:10px; width:800px;height:600px;position:absolute;background-color:#336699;">
     <div id= "divTmp_title" style="width:100%;height:10px;background-color:#3377ff;">远程监控主机:${param.host }</div>
     <div id= "divTmp_content" style="width:100%;height:100%;background-color:#3322ff;" ></div>
     </div>
</body>
</html>
